<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateGreenDevicesTable extends Migration
{
    /**
     * Run the migrations.
     * 绿化基础设施表
     *
     * @return void
     */
    public function up()
    {
        Schema::create('green_devices', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->comment('设施名称')->nullable();
            $table->string('mark',20)->comment('编号')->nullable();
            $table->string('address')->comment('设施位置')->nullable();
            $table->point('location')->comment('设施坐标')->nullable();
            $table->string('type')->comment('设施类型')->nullable();
            $table->tinyInteger('status')->comment('设施状态')->nullable();
            $table->integer('rfid')->unsigned()->comment('RFID绑定')->nullable();
            $table->string('remake')->comment('备注')->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
        Schema::create('green_device_files', function (Blueprint $table) {
            //字段定义
            $table->increments('id');
            $table->integer('green_device_id')->unsigned()->comment('绿化设施id')->nullable();
            $table->foreign('green_device_id')->on('green_devices')->references('id')->onDelete('set null');
            $table->BigInteger('file_id')->unsigned()->comment('图片所属的文件信息')->nullable();
            $table->foreign('file_id')->on('file_upload')->references('id')->onDelete('set null');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('green_devices');
    }
}
